package com.example.ssss.data;

import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.widget.LinearLayout;

import com.example.ssss.R;
import com.example.ssss.data.model.LoggedInUser;
import com.example.ssss.entity.HistoryResponse;
import com.example.ssss.entity.LNH;

import java.io.IOException;

/**
 * Class that handles authentication w/ login credentials and retrieves user information.
 */
public class LoginDataSource {

    public void selectpass(String userid){
        new Thread(){
            @Override
            public void run() {
                super.run();
                MysqlOperation.UserDao userDao=new MysqlOperation.UserDao();
                try {
                    String s=userDao.selectpassword(userid);
                    Message message=new Message();
                    message.obj=s;
                    handler.sendMessage(message);
                } catch (Exception e) {
                    e.printStackTrace();
                }

            }
        }.start();
    }
    public Result<LoggedInUser> login(String userid, String password) {

            // TODO: handle loggedInUser authentication
        password2=password;
        selectpass(userid);
        if(password.equals(password1)){


        }LoggedInUser User =
                new LoggedInUser(userid,password);
//        return new Result.Error(new IOException("Error logging in"));
        return new Result.Success<>(User);
    }

    private String password1,password2;
    private Handler handler=new Handler(){
        @Override
        public void handleMessage(Message msg){
            String s=(String) msg.obj;
            password1=s;
            
        }
    };

    public void logout() {
        // TODO: revoke authentication
    }
}